<template>
    <div class="fillcontain">
<el-form    ref="form" :model="form" style="width:460px;" label-width="80px">
    <!-- personcode:用户名。可为空，为空时修改当前登录帐户的密码。
oldpassword: 旧密码
password: 密码 -->
  <el-form-item label="用户名">
    <el-input v-model="form.personcode" :disabled="true"></el-input>
  </el-form-item>
  <el-form-item label="旧密码">
    <el-input type="password" v-model="form.oldpassword"></el-input>
  </el-form-item>
  <el-form-item label="密码">
    <el-input type="password" v-model="form.password"></el-input>
  </el-form-item>
  <el-form-item label="确认密码">
    <el-input type="password" v-model="form.password2"></el-input>
  </el-form-item>
  <el-form-item>
    <el-button type="primary" @click="onSubmit">修改</el-button>
  </el-form-item>
</el-form>

      
    </div>
</template>
<style>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 110px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>

<script>
    import headTop from '../components/headTop'
    import {getUserList, getUserCount} from '@/api/getData'
    import {updatePersonPwd,addPerson} from '@/api/getData'
    import {getStore} from '@/config/mUtils'
    export default {
        data(){
            return {
                form: {
                    personcode:getStore('personcode'),// 用户名
                    oldpassword:'',//: 用户姓名
                    password:'',//: 密码
                    password2:'',//: 密码
                },
                unitArr:['佳惠'],
                czlxArr:['冻结','解冻'],
                statusArr:['正常','停用'],
                dialogFormVisible:false,
                fullscreenLoading: false,
                addform: {
                    personcode:getStore('personcode'),
                    personname: '',
                    password: '',
                    token: '',
                },
                formLabelWidth: '120px',
                tableData: [
                ],
                currentRow: null,
                offset: 0,
                limit: 20,
                count: 0,
                currentPage: 1,
            }
        },
    	components: {
    		headTop,
    	},
        created(){
            this.initData();
        },
        methods: {
            async initData(){

                try{
                    // const countData = await getUserCount();
                    // if (countData.status == 1) {
                    //     this.count = countData.count;
                    // }else{
                    //     throw new Error('获取数据失败');
                    // }
                }catch(err){
                    console.log('获取数据失败', err);
                }
            },
            async updatePersonPwd(){
                const res = await updatePersonPwd({
                    token:getStore('token'),
                    personcode:this.form.personcode,// 用户名
                    oldpassword:this.form.oldpassword,//: 用户姓名
                    password:this.form.password,//: 密码
                    });
                console.log(res);
                // alert(res.retmsg)
                if (res.retcode='00') {
                    this.$message.error("密码输入不一致！");
                } else {
                    this.$message.error(res.retmsg);
                }
                // this.tableData = [];

               
            },
            //  创建修补单
            onAdd(){ 
                console.log('ddd');
                this.dialogFormVisible = true
            },
            onSubmit(){
                console.log('ddd');
                // row = this.row;
      var p0 = this.form.oldpassword;
      var p1 = this.form.password;
      var p2 = this.form.password2;
      if (!p0) {
        this.$message.error("旧密码不能为空！");
        return;
      }
      if (!p1 || !p2) {
        this.$message.error("密码不能为空！");
        return;
      }
      if (p1 != p2) {
        this.$message.error("密码输入不一致！");
        return;
      }
      this.$confirm("此操作将修改密码, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.updatePersonPwd(); //提交方法
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
                // this.updatePersonPwd()
            },
            
            openFullScreen2() {
                this.loading = this.$loading({
                    lock: true,
                    text: 'Loading',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
                setTimeout(() => {
                    this.loading.close();
                }, 2000);
            }
        },
    }
</script>

<style lang="less">
	@import '../style/mixin';
    .table_container{
        padding: 20px;
    }
</style>
